	function calculate_alpha(betap,X,skipdem) 
	
		# Need to get the premium coefficient alpha for each household
		
		alpha = ones(size(X)[1]) .* betap[findall(all_covariates .== "Premium")[1]]
		
		if !(rich_flag | poor_flag | old_flag | young_flag)
		
			# Income and Age
			if add_complex_interactions
				
				# Income
				if skipdem != "Income"
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_250to400")[1]] .* ((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) ; 	
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_gt400")[1]] .* (households[household_numbers,:FPL] .> 4) ;
				end
				
				# Age
				if skipdem != "Age"
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_0to34")[1]] .* 
							(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_35to54")[1]] .* (households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end	
				
				# Income and Age Interactions
				if !((skipdem == "Income") | (skipdem == "Age"))
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_250to400_0to34")[1]] .*
						((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) .*
						(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_gt400_0to34")[1]] .*
						((households[household_numbers,:FPL] .> 4)) .*
						(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_250to400_35to54")[1]] .*
						((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) .*
						(households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_gt400_35to54")[1]] .*
						((households[household_numbers,:FPL] .> 4)) .*
						(households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end
				
			else
				# Income
				if skipdem != "Income"
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_250to400")[1]] .* ((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) ; 	
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_gt400")[1]] .* (households[household_numbers,:FPL] .> 4) ;
				end
				
				# Age
				if skipdem != "Age"
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_0to17")[1]] .* (households[household_numbers,:perc_0to17]);
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_18to34")[1]] .* (households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					alpha = alpha .+ betap[findall(all_covariates .== "Premium_35to54")[1]] .* (households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end
			end
		end
		
		# Gender
		if skipdem != "Gender"
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_male")[1]] .* (households[household_numbers,:perc_male]);
		end
			
		# Family
		if skipdem != "Family"
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_family")[1]] .* (households[household_numbers,:household_size] .> 1);
		end
			
		# Race
		if skipdem != "Race"
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_Black")[1]] .* (households[household_numbers,:perc_black]);
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_Hispanic")[1]] .* (households[household_numbers,:perc_hispanic]);	
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_Asian")[1]] .* (households[household_numbers,:perc_asian]);	
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_Other")[1]] .* (households[household_numbers,:perc_other]);			
		end
		
		#if random_parameters
		#	alpha = alpha .+ betap[findall(all_covariates .== "Premium_random")[1]] .* V[:,1,1];
		#end
		
		return(alpha)
	end
	
	function calculate_inertia_param(betap,X,skipdem) 
	
		# Need to get the inertia parameter
		
		inertia_param = ones(size(X)[1]) .* betap[findall(all_covariates .== "previous_choice")[1]]
		
		# Put in household characteristics
			
		if !(rich_flag | poor_flag | old_flag | young_flag)	
			
			# Income and Age
			if add_complex_interactions
				
				# Income
				if skipdem != "Income"
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_250to400")[1]] .* ((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) ; 	
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_gt400")[1]] .* (households[household_numbers,:FPL] .> 4) ;
				end
				
				# Age
				if skipdem != "Age"
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_0to34")[1]] .* 
							(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_35to54")[1]] .* (households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end	
				
				# Income and Age Interactions
				if !((skipdem == "Income") | (skipdem == "Age"))
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_250to400_0to34")[1]] .*
						((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) .*
						(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_gt400_0to34")[1]] .*
						((households[household_numbers,:FPL] .> 4)) .*
						(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_250to400_35to54")[1]] .*
						((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) .*
						(households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_gt400_35to54")[1]] .*
						((households[household_numbers,:FPL] .> 4)) .*
						(households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end
				
			else
				# Income
				if skipdem != "Income"
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_250to400")[1]] .* ((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) ; 	
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_gt400")[1]] .* (households[household_numbers,:FPL] .> 4) ;
				end
				
				# Age
				if skipdem != "Age"
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_0to17")[1]] .* (households[household_numbers,:perc_0to17]);
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_18to34")[1]] .* (households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_35to54")[1]] .* (households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end
			end
		end	
			
		# Gender
		if skipdem != "Gender"
			inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_male")[1]] .* (households[household_numbers,:perc_male]);
		end
		
		# Family
		if skipdem != "Family"
			inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_family")[1]] .* (households[household_numbers,:household_size] .> 1);
		end
		
		# Race
		if skipdem != "Race"
			inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_Black")[1]] .* (households[household_numbers,:perc_black]);
			inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_Hispanic")[1]] .* (households[household_numbers,:perc_hispanic]);	
			inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_Asian")[1]] .* (households[household_numbers,:perc_asian]);	
			inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_Other")[1]] .* (households[household_numbers,:perc_other]);			
		end

		# Add product characteristics
		
		if !add_complex_interactions & (skipdem != "Insurer") 
			inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Anthem")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Anthem")[1]];
			inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Blue_Shield")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Blue_Shield")[1]];
			inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Kaiser")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Kaiser")[1]];
			inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Health_Net")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Health_Net")[1]];
			#inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Molina")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Health_Net")[1]];
			#inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Chinese_Community")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Chinese_Community")[1]];
			#inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Sharp")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Sharp")[1]];
			#inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Western_Health")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Western_Health")[1]];
			#inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Oscar")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_Oscar")[1]];
		end
		
		if !add_complex_interactions & (skipdem != "HMO")
			inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "HMO")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_HMO")[1]];
		end
		
		#if skipdem != "Network"
		#	inertia_param = inertia_param .+ betap[findall(all_covariates .== "previous_choice_net")[1]] .*
		#		convert(Array,data[:network_breadth]);
		#end
		
		if !add_complex_interactions
			inertia_param = inertia_param .+ X[:,findall(all_covariates .== "AV")[1]] .* betap[findall(all_covariates .== "previous_choice_AV")[1]];
			#if nested
			#	inertia_param = inertia_param .+ (X[:,findall(all_covariates .== "Silver")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_silver")[1]];
			#end
			#inertia_param = inertia_param .+ X[:,1] .* betap[findall(all_covariates .== "Premium_previous_choice")[1]];
		end

		#inertia_param = inertia_param .* (households[household_numbers,:previous_plan_number] .== "NA"); #.* (1 .- uninsured_plans);
		
		return(inertia_param)
	end
	
	function calculate_av_param(betap,X,skipdem) 
	
		# Need to get the inertia parameter
		
		av_param = ones(size(X)[1]) .* betap[findall(all_covariates .== "AV")[1]]
		
		# Put in household characteristics
			
		if !(rich_flag | poor_flag | old_flag | young_flag)	
			
			# Income and Age
			if add_complex_interactions
				
				# Income
				if skipdem != "Income"
					av_param = av_param .+ betap[findall(all_covariates .== "AV_250to400")[1]] .* ((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) ; 	
					av_param = av_param .+ betap[findall(all_covariates .== "AV_gt400")[1]] .* (households[household_numbers,:FPL] .> 4) ;
				end
				
				# Age
				if skipdem != "Age"
					av_param = av_param .+ betap[findall(all_covariates .== "AV_0to17")[1]] .* (households[household_numbers,:perc_0to17]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_18to34")[1]] .* (households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_35to54")[1]] .* (households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end	
				
				# Income and Age Interactions
				if !((skipdem == "Income") | (skipdem == "Age"))
					av_param = av_param .+ betap[findall(all_covariates .== "AV_250to400_0to34")[1]] .*
						((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) .*
						(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_gt400_0to34")[1]] .*
						((households[household_numbers,:FPL] .> 4)) .*
						(households[household_numbers,:perc_0to17] .+ households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_250to400_35to54")[1]] .*
						((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) .*
						(households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_gt400_35to54")[1]] .*
						((households[household_numbers,:FPL] .> 4)) .*
						(households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end
				
			else
				# Income
				if skipdem != "Income"
					av_param = av_param .+ betap[findall(all_covariates .== "AV_250to400")[1]] .* ((households[household_numbers,:FPL] .> 2.50) .& (households[household_numbers,:FPL] .<= 4)) ; 	
					av_param = av_param .+ betap[findall(all_covariates .== "AV_gt400")[1]] .* (households[household_numbers,:FPL] .> 4) ;
				end
				
				# Age
				if skipdem != "Age"
					av_param = av_param .+ betap[findall(all_covariates .== "AV_0to17")[1]] .* (households[household_numbers,:perc_0to17]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_18to34")[1]] .* (households[household_numbers,:perc_18to25] .+ households[household_numbers,:perc_26to34]);
					av_param = av_param .+ betap[findall(all_covariates .== "AV_35to54")[1]] .* (households[household_numbers,:perc_35to44] .+ households[household_numbers,:perc_45to54]);
				end
			end
		end	
			
		# Gender
		if skipdem != "Gender"
			av_param = av_param .+ betap[findall(all_covariates .== "AV_male")[1]] .* (households[household_numbers,:perc_male]);
		end
		
		# Family
		if skipdem != "Family"
			av_param = av_param .+ betap[findall(all_covariates .== "AV_family")[1]] .* (households[household_numbers,:household_size] .> 1);
		end
		
		# Race
		if skipdem != "Race"
			av_param = av_param .+ betap[findall(all_covariates .== "AV_Black")[1]] .* (households[household_numbers,:perc_black]);
			av_param = av_param .+ betap[findall(all_covariates .== "AV_Hispanic")[1]] .* (households[household_numbers,:perc_hispanic]);	
			av_param = av_param .+ betap[findall(all_covariates .== "AV_Asian")[1]] .* (households[household_numbers,:perc_asian]);	
			av_param = av_param .+ betap[findall(all_covariates .== "AV_Other")[1]] .* (households[household_numbers,:perc_other]);			
		end

		# Add product characteristics
		
		if !add_complex_interactions & (skipdem != "Insurer") 
			av_param = av_param .+ (X[:,findall(all_covariates .== "Anthem")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Anthem")[1]];
			av_param = av_param .+ (X[:,findall(all_covariates .== "Blue_Shield")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Blue_Shield")[1]];
			av_param = av_param .+ (X[:,findall(all_covariates .== "Kaiser")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Kaiser")[1]];
			av_param = av_param .+ (X[:,findall(all_covariates .== "Health_Net")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Health_Net")[1]];
			#av_param = av_param .+ (X[:,findall(all_covariates .== "Molina")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Health_Net")[1]];
			#av_param = av_param .+ (X[:,findall(all_covariates .== "Chinese_Community")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Chinese_Community")[1]];
			#av_param = av_param .+ (X[:,findall(all_covariates .== "Sharp")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Sharp")[1]];
			#av_param = av_param .+ (X[:,findall(all_covariates .== "Western_Health")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Western_Health")[1]];
			#av_param = av_param .+ (X[:,findall(all_covariates .== "Oscar")[1]] .== 1) .* betap[findall(all_covariates .== "AV_Oscar")[1]];
		end
		
		if !add_complex_interactions & (skipdem != "HMO")
			av_param = av_param .+ (X[:,findall(all_covariates .== "HMO")[1]] .== 1) .* betap[findall(all_covariates .== "AV_HMO")[1]];
		end
		
		#if skipdem != "Network"
		#	av_param = av_param .+ betap[findall(all_covariates .== "AV_net")[1]] .*
		#		convert(Array,data[:network_breadth]);
		#end
		
		if !add_complex_interactions
			av_param = av_param .+ X[:,findall(all_covariates .== "AV")[1]] .* betap[findall(all_covariates .== "previous_choice_AV")[1]];
			#if nested
			#	av_param = av_param .+ (X[:,findall(all_covariates .== "Silver")[1]] .== 1) .* betap[findall(all_covariates .== "previous_choice_silver")[1]];
			#end
			#av_param = av_param .+ X[:,1] .* betap[findall(all_covariates .== "Premium_previous_choice")[1]];
		end

		#av_param = av_param .* (households[household_numbers,:previous_plan_number] .== "NA"); #.* (1 .- uninsured_plans);
		
		return(av_param)
	end
	
	
	function get_elasticities_nested_logit(betap,X,alpha,probabilities)
	
		#probabilities = simulate_nested_probabilities(min_beta,X[uninsured_plans .== 0,:],household_numbers[uninsured_plans .== 0],uninsured_plans);	
		lambda = betap[length(betap)];
			
		inside_option_prob = 1 .- probabilities[uninsured_plans .== 1];
		inside_option_probs = inside_option_prob[household_numbers];
			
		ex_probs = probabilities ./ inside_option_probs;
		ex_probs[uninsured_plans .== 1] .= 0;
		
		sizes = households[household_numbers,:enrollees];
		
		# NOTE: set SLC ratio to 0 if there is no subsidy
		SLC_ratio = households[household_numbers,:premiumSLC] ./ (X[:,findall(all_covariates .== "Premium")[1]] .+ subsidies .+ penalties);
		SLC_ratio = ((subsidies .> 0) * 1) .* SLC_ratio;
			
		subs_prem = X[:,findall(all_covariates .== "Premium")[1]];
		unsubs_prem = X[:,findall(all_covariates .== "Premium")[1]] + subsidies + penalties;
		
		own_elasticities_firm = (1/lambda .+ (lambda-1)/lambda * ex_probs .- probabilities) .* (unsubs_prem ./ sizes) .* alpha;
		semi_elasticities_firm = ((100/12) ./ (unsubs_prem ./ sizes)) .* own_elasticities_firm .* 100;
		marketplace_elasticities_firm = (1 .- inside_option_probs) .* (unsubs_prem ./ sizes) .* alpha;
		marketplace_semi_elasticities_firm = ((100/12) ./ (unsubs_prem ./ sizes)) .* marketplace_elasticities_firm .* 100;
		
		return(cat(dims=2,own_elasticities_firm,semi_elasticities_firm,marketplace_elasticities_firm,marketplace_semi_elasticities_firm))
	end
	
	function get_elasticities_logit(betap,X,alpha,probabilities)
		
		inside_option_prob = 1 .- probabilities[uninsured_plans .== 1];
		inside_option_probs = inside_option_prob[household_numbers];
		sizes = households[household_numbers,:enrollees];	
		subs_prem = X[:,findall(all_covariates .== "Premium")[1]];
		unsubs_prem = X[:,findall(all_covariates .== "Premium")[1]] + subsidies + penalties;
		
		own_elasticities_firm = (1 .- probabilities) .* (unsubs_prem ./ sizes) .* alpha;
		semi_elasticities_firm = ((100/12) ./ (unsubs_prem ./ sizes)) .* own_elasticities_firm .* 100;
		marketplace_elasticities_firm = (1 .- inside_option_probs) .* (unsubs_prem ./ sizes) .* alpha;
		marketplace_semi_elasticities_firm = ((100/12) ./ (unsubs_prem ./ sizes)) .* marketplace_elasticities_firm .* 100;
		
		return(cat(dims=2,own_elasticities_firm,semi_elasticities_firm,marketplace_elasticities_firm,marketplace_semi_elasticities_firm))
	end
	
	function get_plan_elasticities(elasticities)
		plan_elasticities = zeros(size(plans)[1],4);
		for plan in plans[!,:Plan_Name]
			plan_indices = findall(data[!,:plan_name] .== plan);
			plan_index_name = findall(plans[!,:Plan_Name] .== plan)[1];
				
			plan_elasticities[plan_index_name,1] = sum(elasticities[plan_indices,1] .* data[plan_indices,:weight]) / sum(data[plan_indices,:weight]);
			plan_elasticities[plan_index_name,2] = sum(elasticities[plan_indices,2] .* data[plan_indices,:weight]) / sum(data[plan_indices,:weight]);
			plan_elasticities[plan_index_name,3] = sum(elasticities[plan_indices,3] .* data[plan_indices,:weight]) / sum(data[plan_indices,:weight]);
			plan_elasticities[plan_index_name,4] = sum(elasticities[plan_indices,4] .* data[plan_indices,:weight]) / sum(data[plan_indices,:weight]);
		end
		return(plan_elasticities)
	end
	
	function compute_plan_shares(probabilities)
		plan_shares = zeros(size(plans)[1]);
		number_insured = sum(probabilities .* data_weights .* (1 .- uninsured_plans));
		for plan in plans[!,:Plan_Name]
			plan_indices = findall(data[!,:plan_name] .== plan);
			plan_index_name = findall(plans[!,:Plan_Name] .== plan)[1];
			plan_shares[plan_index_name] = sum(probabilities[plan_indices] .* data[plan_indices,:weight]) / number_insured;
		end
		return(plan_shares)
	end

	function create_elasticity_table(betap,X,fields)
	
		# Initialize
		output = DataFrame();
		output[!,:Characteristic] = fields ;
		output[!,:Elasticity_Firm] = zeros(length(fields));
		output[!,:Semi_Elasticity_Firm] = zeros(length(fields));
		output[!,:Marketplace_Elasticity_Firm] = zeros(length(fields));
		output[!,:Marketplace_Semi_Elasticity_Firm] = zeros(length(fields));
		
		# Define elasticity function

		if nested
			get_nested_elasticities(alpha) = get_elasticities_nested_logit(betap,X,alpha,probabilities);
		else
			get_logit_elasticities(alpha) = get_elasticities_logit(betap,X,alpha,probabilities);
		end
		
		# Compute plan shares
		plan_shares = compute_plan_shares(probabilities);
		
		# Start with the product characteristics
		alpha = calculate_alpha(betap,X,"All"); 
		if nested
			elasticities = 	get_nested_elasticities(alpha);	
		else
			elasticities = 	get_logit_elasticities(alpha);	
		end
		plan_elasticities = get_plan_elasticities(elasticities);
			
			# Overall
			output[findall(fields .== "Overall")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Overall")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Overall")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Overall")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
				# Fix a small NAN issue here
				elasticities[findall(isnan.(elasticities[:,2])),2] .= 0;
				elasticities[findall(isnan.(elasticities[:,4])),4] .= 0;
			
		# Now we do the individual characteristics
			# We have to calculate the counterfactual alpha
			# Then recompute the elasticities
		
			if add_complex_interactions
			
				alpha_base = calculate_alpha(betap,X,"Income"); 
				alpha = alpha_base;
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "0-250_55+")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "0-250_55+")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "0-250_55+")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "0-250_55+")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
					
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "250-400_55+")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "250-400_55+")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "250-400_55+")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "250-400_55+")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "400+_55+")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "400+_55+")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "400+_55+")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "400+_55+")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_0to34")[1]];
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "0-250_0to34")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "0-250_0to34")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "0-250_0to34")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "0-250_0to34")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_35to54")[1]];
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "0-250_35to54")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "0-250_35to54")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "0-250_35to54")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "0-250_35to54")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400_0to34")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "250-400_0to34")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "250-400_0to34")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "250-400_0to34")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "250-400_0to34")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400_35to54")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "250-400_35to54")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "250-400_35to54")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "250-400_35to54")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "250-400_35to54")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400_0to34")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "400+_0to34")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "400+_0to34")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "400+_0to34")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "400+_0to34")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400_35to54")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "400+_35to54")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "400+_35to54")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "400+_35to54")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "400+_35to54")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
		
			elseif !(rich_flag | poor_flag | old_flag | young_flag)	
		
				# Income
					
				alpha_base = calculate_alpha(betap,X,"Income"); 
				alpha = alpha_base;
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "0-250")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "0-250")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "0-250")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "0-250")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
					
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "250-400")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "250-400")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "250-400")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "250-400")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400")[1],1]; 
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "400+")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "400+")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "400+")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "400+")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				# Age
				
				alpha_base = calculate_alpha(betap,X,"Age");
				alpha = alpha_base;
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;	
				output[findall(fields .== "55+")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "55+")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "55+")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "55+")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_0to17")[1]];
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "0-17")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "0-17")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "0-17")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "0-17")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_18to34")[1]];
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "18-34")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "18-34")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "18-34")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "18-34")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
				
				alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_35to54")[1]];
				if nested
					elasticities = 	get_nested_elasticities(alpha);	
				else
					elasticities = 	get_logit_elasticities(alpha);	
				end
				plan_elasticities = get_plan_elasticities(elasticities) ;
				output[findall(fields .== "35-54")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
				output[findall(fields .== "35-54")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
				output[findall(fields .== "35-54")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
				output[findall(fields .== "35-54")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			end	
				
			# Gender
			
			alpha = calculate_alpha(betap,X,"Gender");
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Female")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Female")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Female")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Female")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_male")[1]];
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Male")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Male")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Male")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Male")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			# Household Size
			
			alpha = calculate_alpha(betap,X,"Family");
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Single")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Single")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Single")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Single")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			alpha = alpha .+ betap[findall(all_covariates .== "Premium_family")[1]];
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Family")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Family")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Family")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Family")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			# Race
			
			alpha_base = calculate_alpha(betap,X,"Race");
			alpha = alpha_base;
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "White")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "White")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "White")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "White")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Asian")[1]];
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Asian")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Asian")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Asian")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Asian")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Black")[1]];
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Black")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Black")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Black")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Black")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Hispanic")[1]];
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Hispanic")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Hispanic")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Hispanic")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Hispanic")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Other")[1]];
			if nested
				elasticities = 	get_nested_elasticities(alpha);	
			else
				elasticities = 	get_logit_elasticities(alpha);	
			end
			plan_elasticities = get_plan_elasticities(elasticities) ;
			output[findall(fields .== "Other")[1],:Elasticity_Firm] = mean(plan_elasticities[:,1]);
			output[findall(fields .== "Other")[1],:Semi_Elasticity_Firm] = mean(plan_elasticities[:,2]);
			output[findall(fields .== "Other")[1],:Marketplace_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,3]);
			output[findall(fields .== "Other")[1],:Marketplace_Semi_Elasticity_Firm] = sum(plan_shares .* plan_elasticities[:,4]);
						
			return(output)
	end
	
	function compute_inertia_cost(alpha,inertia_param,probabilities,data_weights)
		#avg_switching_cost = sum((-inertia_param ./ alpha) .* (probabilities .* data_weights)) ./ sum(probabilities .* data_weights);
		avg_switching_cost = (sum(inertia_param .* probabilities .* data_weights)./sum(probabilities .* data_weights))/
								(sum(alpha .* probabilities .* data_weights)./sum(probabilities .* data_weights));
		return(avg_switching_cost);
	end
	
	function create_inertia_table(betap,X,fields)
	
		# Initialize
		output = DataFrame();
		output[!,:Characteristic] = fields ;
		output[!,:Switching_Cost] = zeros(length(fields));
		
		# Compute plan shares
		plan_shares = compute_plan_shares(probabilities);
		
		# Overall
		
		alpha = calculate_alpha(betap,X,"All"); 
		inertia_param = calculate_inertia_param(betap,X,"All") .* (households[household_numbers,:previous_plan_number] .== "NA"); 
		output[findall(fields .== "Overall")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
		
		if add_complex_interactions
			
			alpha_base = calculate_alpha(betap,X,"Income"); 
			inertia_param_base = calculate_inertia_param(betap,X,"Income") .* (households[household_numbers,:previous_plan_number] .== "NA");  
			
			alpha = alpha_base;
			inertia_param = inertia_param_base;
			output[findall(fields .== "0-250_55+")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_250to400")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "250-400_55+")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_gt400")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "400+_55+")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_0to34")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_0to34")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");	
			output[findall(fields .== "0-250_0to34")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_35to54")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_35to54")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "0-250_35to54")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400_0to34")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_250to400_0to34")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "250-400_0to34")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
				
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400_0to34")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_gt400_0to34")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "400+_0to34")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400_35to54")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_250to400_35to54")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "250-400_35to54")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400_35to54")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_gt400_35to54")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "400+_35to54")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		elseif !(rich_flag | poor_flag | old_flag | young_flag)	
			
			# Income
			
			alpha_base = calculate_alpha(betap,X,"Income"); 
			inertia_param_base = calculate_inertia_param(betap,X,"Income") .* (households[household_numbers,:previous_plan_number] .== "NA");  
			
			alpha = alpha_base;
			inertia_param = inertia_param_base;
			output[findall(fields .== "0-250")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_250to400")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_250to400")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "250-400")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_gt400")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_gt400")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "400+")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			# Age
				
			alpha_base = calculate_alpha(betap,X,"Age");
			inertia_param_base = calculate_inertia_param(betap,X,"Age") .* (households[household_numbers,:previous_plan_number] .== "NA"); 
			
			alpha = alpha_base;
			inertia_param = inertia_param_base;
			output[findall(fields .== "55+")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
				
			alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_0to17")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_0to17")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");	
			output[findall(fields .== "0-17")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
				
			alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_18to34")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_18to34")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "18-34")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
				
			alpha = alpha_base  .+ betap[findall(all_covariates .== "Premium_35to54")[1]];
			inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_35to54")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");
			output[findall(fields .== "35-54")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
		end

		# Race
		
		alpha_base = calculate_alpha(betap,X,"Race");
		inertia_param_base = calculate_inertia_param(betap,X,"Race") .* (households[household_numbers,:previous_plan_number] .== "NA");  
		
		alpha = alpha_base;
		inertia_param = inertia_param_base;
		output[findall(fields .== "White")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Asian")[1]];
		inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Asian")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");		
		output[findall(fields .== "Asian")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Black")[1]];
		inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Black")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");			
		output[findall(fields .== "Black")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Hispanic")[1]];
		inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Hispanic")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");			
		output[findall(fields .== "Hispanic")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		alpha = alpha_base .+ betap[findall(all_covariates .== "Premium_Other")[1]];
		inertia_param = (inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Other")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");			
		output[findall(fields .== "Other")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
		
		# Gender

		alpha = calculate_alpha(betap,X,"Gender");
		inertia_param = calculate_inertia_param(betap,X,"Gender") .* (households[household_numbers,:previous_plan_number] .== "NA");  
		output[findall(fields .== "Female")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		alpha = alpha .+ betap[findall(all_covariates .== "Premium_male")[1]];
		inertia_param = (inertia_param .+ betap[findall(all_covariates .== "previous_choice_male")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");		
		output[findall(fields .== "Male")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		# Family
		
		alpha = calculate_alpha(betap,X,"Family");
		inertia_param = calculate_inertia_param(betap,X,"Family") .* (households[household_numbers,:previous_plan_number] .== "NA");  
		output[findall(fields .== "Single")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		alpha = alpha .+ betap[findall(all_covariates .== "Premium_family")[1]];
		inertia_param = (inertia_param .+ betap[findall(all_covariates .== "previous_choice_family")[1]]) .* (households[household_numbers,:previous_plan_number] .== "NA");			
		output[findall(fields .== "Family")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
					
		# Insurer
		
		if !add_complex_interactions
			alpha_base = calculate_alpha(betap,X,"All"); 
			inertia_param_base = calculate_inertia_param(betap,X,"Insurer"); 
			
			alpha = alpha_base;
			inertia_param = inertia_param_base;
			output[findall(fields .== "Other_Insurer")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base;
			inertia_param = inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Anthem")[1]];		
			output[findall(fields .== "Anthem")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base;
			inertia_param = inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Blue_Shield")[1]];		
			output[findall(fields .== "Blue_Shield")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);

			alpha = alpha_base;
			inertia_param = inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Kaiser")[1]];		
			output[findall(fields .== "Kaiser")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);

			alpha = alpha_base;
			inertia_param = inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_Health_Net")[1]];		
			output[findall(fields .== "Health_Net")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);		
		end	
		
		# HMO
		
		if !add_complex_interactions
			alpha = alpha_base;
			inertia_param_base = calculate_inertia_param(betap,X,"HMO"); 
			
			alpha = alpha_base;
			inertia_param = inertia_param_base;
			output[findall(fields .== "Non-HMO")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
			alpha = alpha_base;
			inertia_param = inertia_param_base .+ betap[findall(all_covariates .== "previous_choice_HMO")[1]];		
			output[findall(fields .== "HMO")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
		end
		
		# Network Breadth
		
		#alpha = calculate_alpha(betap,X,"All");
		#inertia_param_base = calculate_inertia_param(betap,X,"Network"); 
		
		#inertia_param = inertia_param_base;
		#output[findall(fields .== "Breadth0")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		#inertia_param = inertia_param_base .+ 25 * betap[findall(all_covariates .== "previous_choice_net")[1]];	
		#output[findall(fields .== "Breadth25")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		#inertia_param = inertia_param_base .+ 40 * betap[findall(all_covariates .== "previous_choice_net")[1]];
		#output[findall(fields .== "Breadth40")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		#inertia_param = inertia_param_base .+ 60 * betap[findall(all_covariates .== "previous_choice_net")[1]];
		#output[findall(fields .== "Breadth60")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
			
		#inertia_param = inertia_param_base .+ 100 * betap[findall(all_covariates .== "previous_choice_net")[1]];
		#output[findall(fields .== "Breadth100")[1],:Switching_Cost] = compute_inertia_cost(alpha,inertia_param,probabilities,data_weights);
		
		# Convert to annual
		output[!,:Switching_Cost] *= -12; 
		
		return(output)
		
	end
	
	function compute_inertia_correlations(betap,probabilities)
		chosen_plans = intersect(findall(uninsured_plans .== 0),findall(choices .== 1));
		alpha = calculate_alpha(betap,X,"All"); 
		inertia_param = calculate_inertia_param(betap,X,"All") .* (households[household_numbers,:previous_plan_number] .== "NA"); 
		av_param = calculate_av_param(betap,X,"All");
		#cor(av_param[chosen_plans],-inertia_param[chosen_plans] ./ alpha[chosen_plans])
		#cor(av_param[choices .== 1],-inertia_param[choices .== 1] ./ alpha[choices .== 1])
		correlation_matrix = DataFrame(cor(cat(dims=2,av_param[chosen_plans],alpha[chosen_plans],inertia_param[chosen_plans])),:auto);
		#correlation_matrix = DataFrame(cor(cat(dims=2,av_param[choices .== 1],alpha[choices .== 1],inertia_param[choices .== 1])),:auto);
		return(correlation_matrix)
	end